const http = require('http');
const fs = require('fs');
const url = require('url');
const querystring = require('querystring')

http.createServer((req, res) => {
  let path = '';
  let getData = {};
  let postData = {};
  if (req.method == 'GET') {
    let { pathname, query } = url.parse(req.url, true)
    path = pathname;
    getData = query

    complete()
  } else if (req.method == 'POST') {
    path = req.url;
    let arr = [];
    req.on('data', buffer => {
      arr.push(buffer)

    });
    req.on('end', () => {
      let buffer = Buffer.concat(arr)
      postData = querystring.parse(buffer.toString())

      complete()
    })

  }

  function complete() {
    console.log(path, getData, postData);

  }

}).listen(8899)